package com.example.bean;

import java.util.Date;

/**
 * 用户JavaBean（实体类）
 * 符合JavaBean规范：
 * 1. 公共类
 * 2. 无参构造函数
 * 3. 私有属性
 * 4. getter/setter方法
 */
public class User {
    private Integer id;           // 用户id
    private String username;      // 用户名
    private String password;      // 密码
    private String role;          // 角色：admin-管理员，user-普通用户
    private String realname;      // 真实姓名
    private String email;         // 邮箱
    private Date createTime;      // 创建时间

    /**
     * 无参构造函数（JavaBean规范要求）
     */
    public User() {
    }

    /**
     * 全参构造函数
     */
    public User(Integer id, String username, String password, String role, String realname, String email, Date createTime) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.role = role;
        this.realname = realname;
        this.email = email;
        this.createTime = createTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * 判断是否是管理员
     */
    public boolean isAdmin() {
        return "admin".equals(this.role);
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", role='" + role + '\'' +
                ", realname='" + realname + '\'' +
                ", email='" + email + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}

